﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace CMSLibrary.TagsCreate.CustomFunction.Common
{
    /// <summary>
    /// 条件匹配    
    /// 1.  Switch(匹配对象, 条件1┇条件2, 结果1┇结果2)
    /// </summary>
    public class Custom_Switch : PFunctionBase
    {
        #region 参数成员
        /// <summary>
        /// 匹配对象
        /// </summary>        
        string matchobj = string.Empty;
        /// <summary>
        /// 条件集合
        /// </summary>        
        string[] conditions = null;
        /// <summary>
        /// 结果集合
        /// </summary>
        string[] results = null;

        protected const char SplitChar = '┇';  //分隔符
        #endregion

        #region 重写的方法
        protected override void SplitFormatParas(string sourceParas)
        {
            string[] paras = GetParasArray(sourceParas);
            //确定重载方法,由多到少            
            /********** 1 **********/
            try
            {
                matchobj = paras[0];
                conditions = paras[1].Split(SplitChar);
                results = paras[2].Split(SplitChar);
                FunctionBurden = BurdenIndex.one;
                return;
            }
            catch { throw new Exception(); }
        }

        public override string ToString()
        {
            for (int i = 0; i < conditions.Length; i++)
            {
                if (conditions[i] == matchobj) { return results[i];}
            }            
            
            return string.Empty;
        }
        #endregion
    }
}